package org.viva.action.cms;

import java.io.File;
import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.viva.cms.sitemap.BaiduSm;
import org.viva.service.cms.ContentService;
import org.viva.service.cms.SitemapService;

@Controller
public class SitemapAction {

    @Resource
    private ContentService contentService;
    @Resource
    private SitemapService sitemapService;

    @RequestMapping(value = { "/cms/sitemap/create" }, method = RequestMethod.GET)
    public String create(HttpServletRequest request) throws IOException {
        String root = request.getSession().getServletContext().getRealPath("/");
        BaiduSm.createSitemapXml(sitemapService.getList(), root + File.separator + "sitemap.xml");
        return "redirect:/sitemap.xml";
    }

}
